bitkeeper revision 1.1236.1.213 (4251e21boiMcVvsOm7kHtd1O51o1mA)
authorcwc22@centipede.cl.cam.ac.uk <cwc22@centipede.cl.cam.ac.uk>
Tue, 5 Apr 2005 00:55:55 +0000 (00:55 +0000)
committercwc22@centipede.cl.cam.ac.uk <cwc22@centipede.cl.cam.ac.uk>
Tue, 5 Apr 2005 00:55:55 +0000 (00:55 +0000)
Dynamic sizing of a domain's grant map tracking table on demand.
Grant tables now default for block front/back communication.

linux-2.4.29-xen-sparse/arch/xen/defconfig-xen0
linux-2.4.29-xen-sparse/arch/xen/defconfig-xenU
linux-2.6.11-xen-sparse/arch/xen/Kconfig
xen/common/grant_table.c
xen/include/xen/grant_table.h

index b67e52aff68dcd0c6c2f1f142e20863408669749..3e0014cf5e032309cd53547ebaf72c0e365f8a03 100644 (file)
@@ -16,7 +16,7 @@ CONFIG_XEN_PHYSDEV_ACCESS=y
 CONFIG_XEN_SCRUB_PAGES=y
 CONFIG_XEN_NETDEV_FRONTEND=y
 CONFIG_XEN_BLKDEV_FRONTEND=y
-# CONFIG_XEN_BLKDEV_GRANT is not set
+CONFIG_XEN_BLKDEV_GRANT=y
 # CONFIG_XEN_USB_FRONTEND is not set
 CONFIG_NO_IDLE_HZ=y
 CONFIG_FOREIGN_PAGES=y
index a83c1b8392188b1dd4fd70777728c17d3e022d12..61db0a1b653fd84b921d7cbc9e3f5e51722ec747 100644 (file)
@@ -15,7 +15,7 @@ CONFIG_UID16=y
 CONFIG_XEN_SCRUB_PAGES=y
 CONFIG_XEN_NETDEV_FRONTEND=y
 CONFIG_XEN_BLKDEV_FRONTEND=y
-# CONFIG_XEN_BLKDEV_GRANT is not set
+CONFIG_XEN_BLKDEV_GRANT=y
 # CONFIG_XEN_USB_FRONTEND is not set
 CONFIG_NO_IDLE_HZ=y
 # CONFIG_FOREIGN_PAGES is not set
index 9a753a6bf99937efd1ee324998641e0997983076..8205344169d143c3a223b5614b9865ad3e0cd0f6 100644 (file)
@@ -64,12 +64,11 @@ config XEN_BLKDEV_TAP_BE
 config XEN_BLKDEV_GRANT
         bool "Grant table substrate for block drivers (DANGEROUS)"
         depends on !XEN_BLKDEV_TAP_BE
-        default n
+        default y
         help
           This introduces the use of grant tables as a data exhange mechanism
           between the frontend and backend block drivers. This currently
-          conflicts with the block tap, and should be considered untested
-          and likely to render your system unstable.
+          conflicts with the block tap.
 
 config XEN_NETDEV_BACKEND
        bool "Network-device backend driver"
index 446783c48e958453651e7321b614df1800073535..c78720022fc636ff0d1d2d72d9db2e865c7695d5 100644 (file)
@@ -42,7 +42,7 @@ get_maptrack_handle(
     grant_table_t *t)
 {
     unsigned int h;
-    if ( unlikely((h = t->maptrack_head) == NR_MAPTRACK_ENTRIES) )
+    if ( unlikely((h = t->maptrack_head) == t->maptrack_limit) )
         return -1;
     t->maptrack_head = t->maptrack[h].ref_and_flags >> MAPTRACK_REF_SHIFT;
     t->map_count++;
@@ -362,10 +362,30 @@ __gnttab_map_grant_ref(
     /* get a maptrack handle */
     if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
     {
-        put_domain(rd);
-        DPRINTK("No more map handles available\n");
-        (void)__put_user(GNTST_no_device_space, &uop->handle);
-        return GNTST_no_device_space;
+        int              i;
+        grant_mapping_t *new_mt;
+        grant_table_t   *lgt      = ld->grant_table;
+
+        /* grow the maptrack table */
+        if ( (new_mt = (void *)alloc_xenheap_pages(lgt->maptrack_order + 1)) == NULL )
+        {
+            put_domain(rd);
+            DPRINTK("No more map handles available\n");
+            (void)__put_user(GNTST_no_device_space, &uop->handle);
+            return GNTST_no_device_space;
+        }
+
+        memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
+        for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
+            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
+
+        free_xenheap_pages((unsigned long)lgt->maptrack, lgt->maptrack_order);
+        lgt->maptrack          = new_mt;
+        lgt->maptrack_order   += 1;
+        lgt->maptrack_limit  <<= 1;
+
+        printk("Doubled maptrack size\n");
+        handle = get_maptrack_handle(ld->grant_table);
     }
 
 #ifdef GRANT_DEBUG_VERBOSE
@@ -458,7 +478,7 @@ __gnttab_unmap_grant_ref(
 
     map = &ld->grant_table->maptrack[handle];
 
-    if ( unlikely(handle >= NR_MAPTRACK_ENTRIES) ||
+    if ( unlikely(handle >= ld->grant_table->maptrack_limit) ||
          unlikely(!(map->ref_and_flags & MAPTRACK_GNTMAP_MASK)) )
     {
         DPRINTK("Bad handle (%d).\n", handle);
@@ -752,7 +772,7 @@ gnttab_dump_table(gnttab_dump_table_t *uop)
         }
     }
 
-    for ( i = 0; i < NR_MAPTRACK_ENTRIES; i++ )
+    for ( i = 0; i < gt->maptrack_limit; i++ )
     {
         maptrack = &gt->maptrack[i];
 
@@ -860,7 +880,7 @@ gnttab_check_unmap(
 
     rgt = rd->grant_table;
 
-    for ( handle = 0; handle < NR_MAPTRACK_ENTRIES; handle++ )
+    for ( handle = 0; handle < lgt->maptrack_limit; handle++ )
     {
         map = &lgt->maptrack[handle];
 
@@ -1074,8 +1094,10 @@ grant_table_create(
     /* Tracking of mapped foreign frames table */
     if ( (t->maptrack = (void *)alloc_xenheap_page()) == NULL )
         goto no_mem;
+    t->maptrack_order = 0;
+    t->maptrack_limit = PAGE_SIZE / sizeof(grant_mapping_t);
     memset(t->maptrack, 0, PAGE_SIZE);
-    for ( i = 0; i < NR_MAPTRACK_ENTRIES; i++ )
+    for ( i = 0; i < t->maptrack_limit; i++ )
         t->maptrack[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
 
     /* Shared grant table. */
@@ -1121,7 +1143,7 @@ gnttab_release_dev_mappings(grant_table_t *gt)
 
     ld = current->domain;
 
-    for ( handle = 0; handle < NR_MAPTRACK_ENTRIES; handle++ )
+    for ( handle = 0; handle < gt->maptrack_limit; handle++ )
     {
         map = &gt->maptrack[handle];
 
@@ -1191,7 +1213,7 @@ grant_table_destroy(
         /* Free memory relating to this grant table. */
         d->grant_table = NULL;
         free_xenheap_pages((unsigned long)t->shared, ORDER_GRANT_FRAMES);
-        free_xenheap_page((unsigned long)t->maptrack);
+        free_xenheap_page((unsigned long)t->maptrack); //cwc22
         xfree(t->active);
         xfree(t);
     }
index f37d6d4e565cac4987072c10e7e723fa21374293..c273eacadac42e5c3ecaa589dc8c1f9d3e732902 100644 (file)
@@ -66,7 +66,6 @@ typedef struct {
 } grant_mapping_t;
 #define MAPTRACK_GNTMAP_MASK 7
 #define MAPTRACK_REF_SHIFT   3
-#define NR_MAPTRACK_ENTRIES  (PAGE_SIZE / sizeof(grant_mapping_t))
 
 /* Per-domain grant information. */
 typedef struct {
@@ -77,6 +76,8 @@ typedef struct {
     /* Mapping tracking table. */
     grant_mapping_t      *maptrack;
     unsigned int          maptrack_head;
+    unsigned int          maptrack_order;
+    unsigned int          maptrack_limit;
     unsigned int          map_count;
     /* Lock protecting updates to active and shared grant tables. */
     spinlock_t            lock;